﻿using System.Linq;
using Transport.Core.Models.Parcels;
using Transport.Services.Infrastructure;

namespace Transport.Services.Parcels
{
    public class ParcelPackagingItemRepository : RepositoryBase<ParcelPackagingItem>, IParcelPackagingItemRepository
    {
        public ParcelPackagingItemRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {
        }

        public IQueryable<ParcelPackagingItem> Search(string text)
        {
            return string.IsNullOrEmpty(text)
                                ? GetAll().Where(p => p.IsDeleted == false)
                                : GetAll()
                                .Where(p => p.IsDeleted == false && (
                                 p.Parcel.TrackingNumbers.Contains(text)));
        }
    }
}
